<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>桌面式智付通管理系统</title>
    <link rel="shortcut icon" href="../assets/img/favicon-icon.png" />
    <!--<link rel="stylesheet" href="../assets/css/bootstrap-theme.css">-->
    <link rel="stylesheet" href="../assets/css/bootstrap.css">
    <!--[if IE 8]>
    <link rel="stylesheet" href="../assets/css/bootstrapIE8.css">
    <![endif]-->
    <link rel="stylesheet" href="../assets/css/bootstrap-responsive.css">
    <link rel="stylesheet" href="../assets/css/formValidation.css"/>
  	<link rel="stylesheet" href="../assets/css/seuic.css">
    <link rel="stylesheet" href="../assets/css/html/login.css">
</head>
<body>
<div class="floater"></div>
<div class="content col-sm-4 col-sm-offset-4">
    <div class="col-sm-10 col-sm-offset-1 div-login-title">
        <span class="" style="height: 40px;width: 232px;background: url(../assets/img/font.png) no-repeat ;display:inline-block;"></span>
    </div>
    <div class="col-sm-10 col-sm-offset-1 div-login ">
        <form id="defaultForm" method="post" class="form-horizontal">
            <div class="col-sm-12 div-login-form">
                <div class="form-group">
                    <div class="col-sm-12">
                        <input type="text" class="form-control input-userName " id="UserCode" name="UserCode" placeholder="用户名" maxlength="10"  autocomplete="off" required/>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-12">
                        <input type="password" class="form-control input-userPasswd" id="Password" name="Password" placeholder="密码" maxlength="16"  autocomplete="off" required/>
                    </div>
                </div>
                <div class="form-group captcha hidden">
                    <div class="col-sm-12">
                        <input type="text" class="form-control" id="captcha" name="captcha" placeholder="验证码" />
                    </div>
                </div>
                <div class="form-group captcha hidden">
                    <div class="col-sm-12">
                        <a id="refreshCaptcha"><label id="captchaOperation"></label></a>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-12 checkbox">
                        <label><input type="checkbox" id="Remember" name="Remember" checked /> 记住用户名</label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-12 btn-login">
                        <button type="submit" class="btn btn-success btn-block" >登录</button>
                    </div>
                </div>
            </div>

        </form>
    </div>
    <div class="col-sm-10 col-sm-offset-1 div-login-org">
        <label>© 江苏东大集成电路系统工程技术有限公司</label>
    </div>
</div>


    <script src="../assets/js/jquery-1.11.1.min.js"></script>
    <script src="../assets/js/jquery.cookie.js"></script>
    <script src="../assets/js/bootstrap.min.js"></script>

    <script src="../assets/js/formValidation.js"></script>
    <script src="../assets/js/i18n.js"></script>
    <script src="../assets/js/zh_CN.js"></script>

    <script src="../assets/js/framework/bootstrap.js"></script>
    <script src="../assets/js/jquery.md5.js"></script>
    <script src="../assets/js/seuic.js"></script>

    <script>
        $(document).ready(function() {
            ///清除登录信息
            clearAuthCookie();
            ///检查记住状态
            var UserCode = $.cookie("UserCode");
            if (UserCode != "null" && UserCode != undefined) {
                $("#UserCode").val(UserCode);
                $("#captcha").val("");
                $("#Remember").prop("checked",true);
            }
            else{
                //$("#UserCode").val("");
                $("#captcha").val("");
                $("#Remember").prop("checked",false);
            }

            // Generate a simple captcha
            function randomNumber(min, max) {
                return Math.floor(Math.random() * (max - min + 1) + min);
            }

            function randomExpression() {
                return [randomNumber(1, 100), '+', randomNumber(1, 200), '= ?'].join(' ');
            }

            $('#captchaOperation').html(randomExpression());

            $("#refreshCaptcha").on("click",function () {
                $('#captchaOperation').html(randomExpression());
            });

            $('#defaultForm')
                    .formValidation({
                        message: 'This value is not valid',
                        err: {
                            container: 'popover'
                        },
                        icon: {
                            valid: 'glyphicon glyphicon-ok',
                            invalid: 'glyphicon glyphicon-remove',
                            validating: 'glyphicon glyphicon-refresh'
                        },
                        addOns: {
                            i18n: {}
                        },
                        fields: {
                           /* UserCode: {
                                validators: {
                                    notEmpty: {
                                        message: {zh_CN:'请输入用户名'}
                                    }
                                }
                            },
                            Password: {
                                validators: {
                                    notEmpty: {
                                        message: {zh_CN:'请输入密码'}
                                    }
                                }
                            }*/
                            /*,
                            captcha: {
                                validators: {
                                    callback: {
                                        message: '回答错误',
                                        callback: function(value, validator, $field) {
                                            var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
                                            return value == sum;
                                        }
                                    }
                                }
                            }*/
                        }
                    })
                    .formValidation('setLocale', 'zh_CN')
                    .on('success.form.fv', function(e) {
                        e.preventDefault();
                        var $form = $(e.target);
                        var bv = $form.data('formValidation');
                        var pwdObj = $('#Password');
                        var pwd = pwdObj.val();
                        pwdObj.val(hash(pwd));
                        var data = $form.serializeArray();
                        $.ajax({
                            data: data,
                            type: "post",
                            url: globalUrl+"api/Login",
                            dataType: "json",
                            success: function (resp) {
                                if(resp.result)
                                {
                                    setAuthCookie(resp);

                                    if ($("#Remember").prop("checked")) {
                                        $.cookie("UserCode", resp.data["UserCode"], { expires: globalCookieTime });
                                    }
                                    else{
                                        $.cookie("UserCode",null);
                                    }
                                    location.href="./index.html";
                                }
                                else
                                {
                                    alert(resp["msg"]);
                                }
                            },
                            complete: function () {
                                //$("loading").hide();
                            },
                            error:function(a,b,c){
                                console.log(a);
                                console.log(b);
                                console.log(c);
                                alert("获取数据失败！");
                            }
                        });
                    });
        });

    </script>
<script src="../assets/js/placeholderForIEPassword.js"></script>
</body>
</html>
